import store from '@/store'
function hasPermission(value, el = false) {
    if (!Array.isArray(value)) {
        throw new Error(`需要配置权限，例如v-permission=['getStatistics3,GET']`)

    }
    const hasAuth = value.findIndex(item => store.state.ruleNames.includes(item
    )) != -1
    if (el && !hasAuth) {
        el.parentNode && el.parentNode.removeChild(el)
    }
    return hasAuth
}



export default {
    install(app) {
        // console.log(app)
        app.directive('permission', {
            mounted(el, binding) {
                // console.log(el, binding)
                //  binding.value
                hasPermission(binding.value,el)

            }
        })
    }
}